import { createRouter, createWebHistory } from "vue-router";

const routes = [
  { path: "/", redirect: "/404" },

  {
    path: "/404",
    name: "404",
    component: () => import("../views/404.vue"),
  },
];

const router = createRouter({
  history: createWebHistory(),
  routes,
});

//路由钩子 跳转页面不存在 就跳转404
router.beforeEach((to, from, next) => {
  if (to.matched.length === 0) {
    next("/404");
  } else {
    next();
  }
});

export default router;
